package com.wx.mall.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wx.mall.sys.entity.BasicSetting;
import com.wx.mall.sys.mapper.BasicSettingMapper;
import com.wx.mall.sys.service.IBasicSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author j
 * @since 2020-03-17
 */
@Service
public class BasicSettingServiceImpl extends ServiceImpl<BasicSettingMapper, BasicSetting> implements IBasicSettingService {

    @Autowired
    private BasicSettingMapper basicSettingMapper;

    @Override
    public BasicSetting get() {
        List<BasicSetting> list = basicSettingMapper.selectList(new QueryWrapper<BasicSetting>());
        if(list.size()>0){
            return list.get(0);
        }
        return new BasicSetting();
    }

    @Override
    @Transactional
    public void save2(BasicSetting basicSetting) {
        delete();
        basicSettingMapper.insert(basicSetting);
    }

    @Override
    public void delete() {
        basicSettingMapper.delete(new QueryWrapper<BasicSetting>());
    }
}
